/*
 * Ethan Levine
 * 
 * The contents of this file are subject to the GNU General Public
 * License (GPL) v2.  The full contents of this license can be
 * found at Mathma's website, http://www.codeplex.com/mathma/license
 */
package mathma.core.expr;

import mathma.core.value.Value;
import mathma.core.value.ValueType;

import java.util.ArrayList;
import java.util.List;

/**
 * @since 0.1.0
 * @author Ethan Levine
 */
public abstract class Variable<E extends Value> extends Expression<E> {

    private String symbol;
    private String description;
    private int id;
    private static int nextId = 1;

    protected Variable(String symbol, ValueType type) {
        super(type, ExpressionType.SYMBOLIC);
        this.symbol = symbol;
        description = symbol;
        id = 0;
    }

    protected Variable(String symbol, String description, ValueType type) {
        super(type, ExpressionType.SYMBOLIC);
        this.symbol = symbol;
        this.description = description;
        id = 0;
    }

    protected Variable(ValueType type) {
        super(type, ExpressionType.SYMBOLIC);
        id = nextId;
        nextId++;
        symbol = "<" + id + ">";
        description = "<" + id + ">";
    }

    public int id() {
        return id;
    }

    public String symbol() {
        return symbol;
    }

    public String description() {
        return description;
    }

    @Override
    public boolean equals(Object other) {
        Variable v = (Variable) other;
        if (id > 0 || v.id() > 0) {
            return id == v.id();
        } else {
            return (symbol.equals(v.symbol())) && (description.equals(v.description()));
        }
    }

    public E evaluate() {
        throw new UnknownValueException("Class Variable carries no value.");
    }

    @Override
    public Expression<E> simplify() {
        return this;
    }
}
